<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north'" style=" height:40px;padding:10px; border-top:0;border-left:0;border-right:0; overflow:hidden">
         <div style="font-size:15px; font-weight:bold;">当前工作名称：<?php echo urldecode($run_title);?></div>
    </div>
    <div data-options="region:'south'" style="height:40px; padding:5px; border-width:1px 0 0 0; overflow:hidden">
    	<div style="float:left; font-size:14px; font-weight:bold;font-family:'Microsoft Yahei'; padding-top:5px;">
        	<input id="workflow_next_select_id" type="hidden" value="">
        	<div style="float:left;">下一步办理人：</div>
            <div id="workflow_next_select_user" style="float:left; color:#F00;"></div>
        </div>
        <div style="float:right;">
    		<a id="next_handed_btn" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:flow_transact_next()" style="width:80px">确定</a>
        	<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#dialog_custom_box').dialog('close'); " style="width:80px">取消</a>
        </div>
    </div>
    <div data-options="region:'west',collapsible:false,title:'流程列表',split:true" style="width:230px;border-left:0; ">
   <div id="csh"></div>
    </div>
    <div data-options="region:'center',border:false" style="padding:0;border-left:0;border-right:0;">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'east',split:true" style="width:210px"><div id="workflow_selectuser_list" class="easyui-datagrid" title="单击部门名称或勾选" border="false"></div></div>
            <div data-options="region:'center',title:'选择部门'" style="padding:10px;">
                <ul id="workflow_selectuser_tree" class="easyui-tree" data-options="
                    url:'<?php echo base_url('systemmanage/dept_data')?>',
                    animate:true,
                    checkbox:false,
                    fit:true
                "></ul>
            </div>
        </div>
    </div>
</div>
<script>
$("#csh").load("<?php echo base_url('workflow/flow_chart').'/'.$run_id.'/1';?>");

$('#workflow_selectuser_tree').tree({
	onSelect : function(node) {
		//返回树对象
		var tree = $(this).tree;
		//选中的节点是否为叶子节点,如果不是叶子节点,清除选中
		var isLeaf = tree('isLeaf', node.target);
		if (!isLeaf) {
			//清除选中
			$('#workflow_selectuser_tree').tree('toggle',node.target);
			//$.messager.alert('警告','请选择子部门!','warning');
		}else{			
			$('#workflow_selectuser_tree').tree({
				onClick: function(node){
					//alert(node.text);  // alert node text property when clicked
					$('#workflow_selectuser_list').datagrid({
						url:'<?php echo base_url('systemmanage/user_data');?>/'+node.id,
						title:node.text+' 用户列表',
						showHeader:false,
						loadMsg:'加载中',
						nowrap:false,
						singleSelect:true,
						fit:true,
						fitColumns:true,
						border:false,
						columns:[[
							{field:'user_name',width:180,align: 'center'}
						]],
						onClickRow:function(index,data){
							if(data.id == '<?php echo $this_username;?>'){
								$.messager.alert('警告','不允许转给自己!','warning');
								$('#workflow_selectuser_list').datagrid("unselectRow", index);//
							}else{
								if(data.id){   /*如果返回列表，则执行插入用户和选中动作，否则不许插入并取消选中*/
									workflow_click_user(data,index);	
								}else{
									$('#workflow_selectuser_list').datagrid("unselectRow", index);//
								}
							}
						}
					});
				}
			});
		}
	},
	onCheck:function(node, checked){ 
		if(checked){
			$.get("<?php echo base_url('selectuser/getcheckeduser');?>/"+node.id,function(result){
				add_all(result);
			},'json');
		}else{
			$.get("<?php echo base_url('selectuser/getcheckeduser');?>/"+node.id,function(result){
				del_all(result);	
			},'json');
		}
	} 		
});

//单击选择下一步办理人
function workflow_click_user(data,index){
	var click_id = $("#workflow_next_select_id").val();
	//if(click_id != ''){
		if(click_id.indexOf(data.id)>=0){//源表单数据位0个或多于0个执行以下操作
			$("#workflow_next_select_id").val('');
			$("#workflow_next_select_user").empty();
			$('#workflow_selectuser_list').datagrid("unselectRow", index);//
		}else{
			$("#workflow_next_select_id").val(data.id);
			$("#workflow_next_select_user").empty().text(data.user_name);
		}
	//}else{
	//	$("#workflow_next_select_id").val(data.id);
	//	$("#workflow_next_select_user").text(data.user_name);
	//}
}

//选择下一步办理人后，点击确定执行的操作：
function flow_transact_next(){
	
	var run_id = '<?php echo $run_id;?>';
	var ps_id = '<?php echo $ps_id;?>';
	var ps_userid = $("#workflow_next_select_id").val();
	var ps_username = $("#workflow_next_select_user").text();
	var run_title = '<?php echo urldecode($run_title);?>'
	
	if(ps_userid == ''){
		$.messager.alert('提示','请选择办理人!','info');	
		return false;	
	}
	$('#next_handed_btn').linkbutton('disable');	
	$.post("<?php echo base_url('workflow/flow_next');?>",{
		run_id:run_id,
		ps_id:ps_id,
		ps_userid:ps_userid,
		ps_username:ps_username,
		run_title:run_title
	},function(data){
		if(data.success){
			//转交下一步成功后，关闭当前对话框，关闭当前办理的工作面板，刷新工作流列表
			workflow_if_removePanel(run_id);
			$('#dialog_custom_box').dialog('close');  //关闭对话框
			//$('#main_workflow_list').datagrid('reload');  
			//$('#workflow_list').datagrid('reload');  	
			
			module_refresh_sms("工作流","workflow_list")
		}else{
			$.messager.alert('警告',data.errorMsg,'warning');
			$('#next_handed_btn').linkbutton('enable');
		}
	},'JSON');
}
</script>
